import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'homes',
    component: HomeView,
    redirect:'/home'
  },
  {
    path: '/home',
    name: 'home',
    component: () => import(/* webpackChunkName: "about" */ '../views/home/index')
    
  },
  {
    path: '/home/brand',
    name: 'homeBrand',
    component: () => import(/* webpackChunkName: "about" */ '../views/home/brand/index')
    
  },
  {
    path: '/home/brandList',
    name: 'homeBrandList',
    component: () => import(/* webpackChunkName: "about" */ '../views/home/brand/brandList/index')
    
  },
 
  {
    path: '/home/search',
    name: 'homeSearch',
    component: () => import(/* webpackChunkName: "about" */ '../views/home/search/index')
    
  },
  {
    path: '/home/goodsDetail',
    name: 'homeGoodsDetail',
    component: () => import(/* webpackChunkName: "about" */ '../views/home/goodsDetail/index')
    
  },
  {
    path: '/home/map',
    name: 'homeMap',
    component: () => import(/* webpackChunkName: "about" */ '../views/home/mapGuide/index')
    
  },
  {
    path: '/home/list',
    name: 'homeList',
    component: () => import(/* webpackChunkName: "about" */ '../views/home/list/index')
    
  },
  {
    path: '/cart',
    name: 'cart',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/cart/index')

  },
  {
    path: '/cart/order',
    name: 'cartOrder',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/cart/order/index.vue')
  },
  {
    path: '/cartGory',
    name: 'cartGory',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/cartgory/index')

  },
  {
    path: '/cartGory/list',
    name: 'cartGoryList',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/cartgory/list/index')

  },
  {
    path: '/topic',
    name: 'topic',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/topic/index')
  },
  {
    path: '/topic/topList',
    name: 'topicTopList',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/topic/topList/index')
  },
  {
    path: '/user',
    name: 'user',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/user/index')
  },
 
  {
    path: '/user/address',
    name: 'userAddress',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/user/address/index.vue'),
  },
  {
    path: '/user/collect',
    name: 'userCollect',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/user/collect/index.vue'),
  },
  {
    path: '/user/opinion',
    name: 'userOpinion',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/user/opinion/index.vue'),
  },
  
]

const router = new VueRouter({
  routes,
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})

export default router
